package com.multidisplay.controller;

import com.multidisplay.bo.LoginBo;
import com.multidisplay.bo.ResultBo;
import com.multidisplay.po.User;
import com.multidisplay.pojo.AddUser;
import com.multidisplay.pojo.Login;
import com.multidisplay.service.impl.LoginServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@CrossOrigin
@Api(tags="登陆页面接口")
public class LoginController {
    @Autowired
    private LoginServiceImpl loginService;

    @RequestMapping("/userlogin")
    @ResponseBody
    @ApiOperation("用户登录")
    public ResultBo<LoginBo> login(@RequestParam("username") String username,@RequestParam("password") String password, HttpSession session){
        Login login=new Login();
        login.setUsername(username);
        login.setPassword(password);
        ResultBo<LoginBo> resultBo=loginService.login(login);
        session.setAttribute("res",resultBo);
        return resultBo;
    }

    @PutMapping("/userregister")
    @ApiOperation("用户注册")
    public LoginBo register(AddUser addUser){
        LoginBo loginBo=loginService.register(addUser);
        return loginBo;
    }
}
